package com.wu.Backstage.entity;

import com.wu.Backstage.entity.Po.CommodityEntityPo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


@Transactional
public interface CommodityEntityJp extends JpaRepository<CommodityEntityPo, Integer> {


    @Query("from CommodityEntityPo where state = ?1 and sta = ?2")
    List<CommodityEntityPo> findCommodityEntityPoSta(Integer sta,Integer st);


    @Query("from CommodityEntityPo where state = 1 and sta = 0 and type = ?1 and region = ?2")
    List<CommodityEntityPo> findCommodityEntityType(String type,String region);


    @Query("from CommodityEntityPo where resource = ?1")
    List<CommodityEntityPo> findCommodityEntityResource(String res);


    @Modifying
    @Query("update CommodityEntityPo set state = 1 ,sta = 0 where id = ?1")
    int UpCommodityEntity(Integer id);


    @Modifying
    @Query("update CommodityEntityPo set sta = 1 where id = ?1")
    int UpCommodityEntitysta(Integer id);



    @Modifying
    @Query(value = "select t_id as id, t_dity_id as dityId from tbl_commodity where t_state = 1 and t_sta =0",nativeQuery = true)
    ArrayList<HashMap<String,Object>> findCommodityEntityPoSp(Integer sta, Integer st);












}
